#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int HalfSort(const vector<int>& nums, int target)
    {
        int left = 0;
        int right = nums.size() - 1;
        while (left <= right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] == target)
                return mid;
            else if (nums[mid] < target)
                left = mid + 1;
            else if (nums[mid] > target)
                right = mid - 1;
            else
                break;
        }
        return -1;
    }
    int search(vector<int>& nums, int target) {
        int i = 0;
        i = HalfSort(nums, target);
        if (i == -1)
            return 0;
        int count = 0;
        int left = i - 1;
        int right = i + 1;
        while (left >= 0 || right < nums.size())
        {
            if (left >= 0 && nums[left] == target)
                count++;
                left--;
            if (right < nums.size() && nums[right] == target)
                count++;
            if ((left >= 0 && right < nums.size()) && (nums[left] != target && nums[right] != target))
                break;
            if(left >= 0)
                left--;
            if(right < nums.size())
                right++;
        }
        return count + 1;
    }
};
int main()
{
    vector<int> nums = { 1, 3 };
    cout << Solution().search(nums, 1) << endl;
    return 0;
}